package com.beyond.trace.dy.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.beyond.trace.dy.domain.TraceDySale;
import com.beyond.trace.dy.service.ITraceDySaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售单Controller
 * 
 * @author Mr.Yao
 * @date 2022-04-09
 */
@RestController
@RequestMapping("/dy/sale")
@Api(value = "销售单", tags = "销售单")
public class TraceDySaleController extends BaseController
{
    @Autowired
    private ITraceDySaleService traceDySaleService;

    //@PreAuthorize("@ss.hasPermi('dy:sale:list')")
    @GetMapping("/list")
    @ApiOperation("查询销售单列表")
    public TableDataInfo list(TraceDySale traceDySale)
    {
        startPage();
        List<TraceDySale> list = traceDySaleService.selectTraceDySaleList(traceDySale);
        return getDataTable(list);
    }

    //@PreAuthorize("@ss.hasPermi('dy:sale:query')")
    @GetMapping(value = "/query")
    @ApiOperation("查询销售单列表不分页")
    public AjaxResult getInfoQuery(TraceDySale traceDySale)
    {
        return AjaxResult.success(traceDySaleService.selectTraceDySaleList(traceDySale));
    }

    //@PreAuthorize("@ss.hasPermi('dy:sale:export')")
    @Log(title = "销售单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceDySale traceDySale)
    {
        List<TraceDySale> list = traceDySaleService.selectTraceDySaleList(traceDySale);
        ExcelUtil<TraceDySale> util = new ExcelUtil<TraceDySale>(TraceDySale.class);
        return util.exportExcel(list, "销售单数据");
    }

    //@PreAuthorize("@ss.hasPermi('dy:sale:query')")
    @GetMapping(value = "/{saleId}")
    @ApiOperation("查询销售单列表")
    public AjaxResult getInfo(@PathVariable("saleId") Long saleId)
    {
        return AjaxResult.success(traceDySaleService.selectTraceDySaleById(saleId));
    }

    //@PreAuthorize("@ss.hasPermi('dy:sale:add')")
    @Log(title = "销售单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增销售单")
    public AjaxResult add(@RequestBody TraceDySale traceDySale)
    {
        return toAjax(traceDySaleService.insertTraceDySale(traceDySale));
    }

    //@PreAuthorize("@ss.hasPermi('dy:sale:edit')")
    @Log(title = "销售单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改销售单")
    public AjaxResult edit(@RequestBody TraceDySale traceDySale)
    {
        return toAjax(traceDySaleService.updateTraceDySale(traceDySale));
    }

    //@PreAuthorize("@ss.hasPermi('dy:sale:remove')")
    @Log(title = "销售单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saleIds}")
    @ApiOperation("删除销售单")
    public AjaxResult remove(@PathVariable Long[] saleIds)
    {
        return toAjax(traceDySaleService.deleteTraceDySaleByIds(saleIds));
    }
}
